<div>
    <div id="editForm" class="form-horizontal">

        <input type="hidden" class="form-control" value="{{mod.id}}" name="id" />

        <div class="form-group">
            <label class="col-lg-12 control-label">角色</label>
            <div class="col-lg-12">
                <select class="form-control" name="role"  >
                  
                    <option value="user">user</option>
                    <option value="admin">admin</option>
                  
                </select>

            </div>
        </div>

     


        <div class="form-group">
            <label class="col-lg-12 control-label">用户名</label>
            <div class="col-lg-12">
                <input type="text" class="form-control" name="name" placeholder="标题"  value="{{mod.name}}" data-bv-field="name">

            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-12 control-label">头像</label>
            <div class="col-lg-12">
                <input id="filezh" name="file-zh[]" type="file" data-bv-field="filezh">
                <input type="hidden" class="form-control" name="avatar" id="avatar" value="{{mod.avatar}}" >
                <div id="divImg">

                </div>
                <script>
                    //初始化fileinput
                    var FileInput = function () {
                        var oFile = new Object();

                        //初始化fileinput控件（第一次初始化）
                        oFile.Init = function (ctrlName, uploadUrl) {
                            var control = $('#' + ctrlName);

                            //初始化上传控件的样式
                            control.fileinput({
                                language: 'zh', //设置语言
                                uploadUrl: uploadUrl, //上传的地址
                                allowedFileExtensions: ['jpg', 'gif', 'png'], //接收的文件后缀
                                showUpload: true, //是否显示上传按钮
                                showCaption: false, //是否显示标题
                                browseClass: "btn btn-primary", //按钮样式     
                                dropZoneEnabled: false, //是否显示拖拽区域
                                //minImageWidth: 50, //图片的最小宽度
                                //minImageHeight: 50,//图片的最小高度
                                //maxImageWidth: 1000,//图片的最大宽度
                                //maxImageHeight: 1000,//图片的最大高度
                                //maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
                                //minFileCount: 0,
                                //maxFileCount: 10, //表示允许同时上传的最大文件个数
                                enctype: 'multipart/form-data',
                                validateInitialCount: true,
                                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                                msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
                            });

                            //导入文件上传完成之后的事件
                            control.on("fileuploaded", function (event, data, previewId, index) {

                              
                                var img = data.response.data;
                                console.log(img);

                                if (img == undefined) {
                                    toastr.error('上传失败');
                                    return;
                                }
                                $("#avatar").val(img);
                                $("#divImg").html("<img style='height:50px' src='" + img + "'/>");
                                
                            });
                        }
                        return oFile;
                    };



                    $(function () {

                        var url = '/manage/uploadSingle';
                        var allowedFileExtensions = ['jpg', 'png', 'gif', 'jpeg'];

                        var oFileInput = new FileInput();
                        oFileInput.Init("filezh", url);


                        //fileUpload('jobTable', 'filezh', url, 20, 50000000, allowedFileExtensions);
                    });
                </script>

            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 control-label">邮箱</label>
            <div class="col-lg-12">
                <input type="text" class="form-control" name="email" placeholder="邮箱"  value="{{mod.email}}" data-bv-field="email">

            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 control-label">微博</label>
            <div class="col-lg-12">
                <input type="text" class="form-control" name="weibo" placeholder="微博"  value="{{mod.weibo}}" data-bv-field="weibo">

            </div>
        </div>

       

        <div class="form-group">
            <label class="col-lg-12 control-label">简介</label>
            <div class="col-lg-12">
                <input type="text" class="form-control" name="introduce" placeholder="简介" data-bv-field="introduce"  value="{{mod.introduce}}">

            </div>
        </div>


    </div>
</div>




<script>
    $(function () {
      

        var img= '{{mod.avatar}}';
        if(img!=''){

            $("#avatar").val(img);
            $("#divImg").html("<img style='height:50px' src='" + img + "'/>");

        }

        $('select[name="role"]').val('{{mod.role}}');


        $('#editForm').bootstrapValidator({
            phones: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    message: '排序校验失败',
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        }
                    }
                },
                imgUrl: {
                    message: '内容校验失败',
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        stringLength: {
                            min: 2,
                            max: 50,
                            message: '长度2-50位字符'
                        }
                    }
                }

            }
        });

    });




    function ajaxSubmitForm() {

        var id = $('input[name="id"]').val();
        var name = $('input[name="name"]').val();
        var weibo = $('input[name="weibo"]').val();
        var email = $('input[name="email"]').val();
        var introduce= $('input[name="introduce"]').val();
        var avatar= $('input[name="avatar"]').val();
        var role= $('select[name="role"]').val();
    
        var param = {
            'id': id,
            'name': name,
            'weibo': weibo,
            'email': email,
            'introduce': introduce,
            'avatar': avatar,
            'role': role
        };
        var url = 'edit';

        console.log(param);
        var resultInfo = ajaxPost(url, param, false);
        return resultInfo;
    }
</script>